#!/bin/bash
yum install -y zlib-devel gcc gcc-c++ 
groupadd www
useradd -s /sbin/nologin -g www www
mkdir -p /data/static
cd src/
tar zxvf pcre-8.38.tar.gz
tar zxvf openssl-1.0.2h.tar.gz
tar zxvf nginx-1.12.1.tar.gz 
cd nginx-1.12.1
# close debug
sed -i 's@CFLAGS="$CFLAGS -g"@#CFLAGS="$CFLAGS -g"@' auto/cc/gcc
./configure --prefix=/usr/local/nginx  --conf-path=/usr/local/nginx/etc/nginx.conf --user=www --group=www \
--with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-http_realip_module \
--with-http_flv_module --with-pcre=../pcre-8.38 --with-pcre-jit \
--http-client-body-temp-path=/usr/local/nginx/var/client_body_temp --http-proxy-temp-path=/usr/local/nginx/var/proxy_temp \
--http-fastcgi-temp-path=/usr/local/nginx/var/fastcgi_temp --http-uwsgi-temp-path=/usr/local/nginx/var/uwsgi_temp \
--http-scgi-temp-path=/usr/local/nginx/var/scgi_temp \
--http-log-path=/usr/local/nginx/var/logs/nginx.access.log \
--with-openssl=../openssl-1.0.2h \
--with-http_stub_status_module \
--with-http_sub_module
make
make install
cd ..
rm pcre-8.38 -rf
rm openssl-1.0.2h -rf
rm nginx-1.12.1 -rf
cd ..
rm -f /usr/local/nginx/etc/nginx.conf
cp conf/nginx.conf /usr/local/nginx/etc/nginx.conf
rm -f /usr/local/nginx/etc/conf.d/default.conf
cp conf/default.conf  /usr/local/nginx/etc/conf.d/default.conf
rm -f /usr/local/nginx/etc/proxy.conf
cp conf/proxy.conf /usr/local/nginx/etc/proxy.conf
rm -f /etc/init.d/nginx
cp init.d/nginx /etc/init.d/ 
mkdir -p /usr/local/nginx/etc/conf.d
service nginx start
rm -f /etc/sysctl.d/nginx.sysctl.conf
cp conf/nginx.sysctl.conf /etc/sysctl.d/
sysctl --system > /dev/null


